package com.camelot.boot.module.system.service.chatmessage1;

import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.camelot.boot.module.system.controller.admin.chatmessage1.vo.*;
import com.camelot.boot.module.system.dal.dataobject.chatmessage1.ChatMessage1DO;
import com.camelot.boot.framework.common.pojo.PageResult;
import com.camelot.boot.framework.common.pojo.PageParam;
import com.camelot.boot.framework.common.util.object.BeanUtils;

import com.camelot.boot.module.system.dal.mysql.chatmessage1.ChatMessage1Mapper;

import static com.camelot.boot.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.camelot.boot.module.system.enums.ErrorCodeConstants.*;

/**
 * AI 聊天消息 Service 实现类
 *
 * @author 管理员
 */
@Service
@Validated
public class ChatMessage1ServiceImpl implements ChatMessage1Service {

    @Resource
    private ChatMessage1Mapper chatMessage1Mapper;

    @Override
    public Long createChatMessage1(ChatMessage1SaveReqVO createReqVO) {
        // 插入
        ChatMessage1DO chatMessage1 = BeanUtils.toBean(createReqVO, ChatMessage1DO.class);
        chatMessage1Mapper.insert(chatMessage1);
        // 返回
        return chatMessage1.getId();
    }

    @Override
    public void updateChatMessage1(ChatMessage1SaveReqVO updateReqVO) {
        // 校验存在
        validateChatMessage1Exists(updateReqVO.getId());
        // 更新
        ChatMessage1DO updateObj = BeanUtils.toBean(updateReqVO, ChatMessage1DO.class);
        chatMessage1Mapper.updateById(updateObj);
    }

    @Override
    public void deleteChatMessage1(Long id) {
        // 校验存在
        validateChatMessage1Exists(id);
        // 删除
        chatMessage1Mapper.deleteById(id);
    }

    private void validateChatMessage1Exists(Long id) {
        if (chatMessage1Mapper.selectById(id) == null) {
            throw exception(CHAT_MESSAGE1_NOT_EXISTS);
        }
    }

    @Override
    public ChatMessage1DO getChatMessage1(Long id) {
        return chatMessage1Mapper.selectById(id);
    }

    @Override
    public PageResult<ChatMessage1DO> getChatMessage1Page(ChatMessage1PageReqVO pageReqVO) {
        return chatMessage1Mapper.selectPage(pageReqVO);
    }

}